import Vue from 'vue'
import VueRouter from 'vue-router'
import HomeView from '../views/index.vue'


// [解决 vue-router跳转相同路径报错 ]
const originalPush = VueRouter.prototype.push
VueRouter.prototype.push = function push (location, onResolve, onReject) {
  if (onResolve || onReject) return originalPush.call(this, location, onResolve, onReject)
  return originalPush.call(this, location).catch(err => err)
}

Vue.use(VueRouter)

const routes = [
  //访问意料之外的路由时重定向到/
  {
    path: '*',
    redirect: '/'
  },
  {
    path: '/',
    name: 'home',
    component: HomeView,
    hidden: true,
    meta: {
      keepAlive: false,
      login: true,
      title: '学历报名'
    }
  },
  // 公众号相关接口  登录
  {
    name:'login',
    path: '/login',
    component: (resolve) => require(['@/views/signUp/education/index'], resolve),
    hidden: true,
    meta: {
      keepAlive: false,
      login: false,
      title: '学历报名登录'
    }
  },
  {
    name:'register',
    path: '/register',
    component: (resolve) => require(['@/views/register/index'], resolve),
    hidden: true,
    meta: {
      keepAlive: false,
      login: false,
      title: '学历报名注册'
    }
  }, // 学历报名入口 扫码
  {
    name:'signUp',
    path: '/signUp',
    component: (resolve) => require(['@/views/signUp/education/index'], resolve),
    hidden: true,
    meta: {
      keepAlive: false,
      login: false,
      title: '学历报名'
    }
  }, // 查询入口
  {
    name:'signUpQueryIndex',
    path: '/signUpQueryIndex',
    component: (resolve) => require(['@/views/signUp/education/query'], resolve),
    hidden: true,
    meta: {
      keepAlive: false,
      login: false,
      title: '报名查询'
    }
  },
  { // 学历报名修改页面
    name:'signUpEducationUpdateIndex',
    path: '/signUpEducationUpdateIndex',
    component: (resolve) => require(['@/views/signUp/education/update'], resolve),
    hidden: true,
    meta: {
      keepAlive: false,
      login: false,
      title: '报名查询'
    }
  },
  { // 资格证书报名入口
    name:'signUpQualificationCertificate',
    path: '/signUp/qualificationCertificate',
    component: (resolve) => require(['@/views/signUp/qualificationCertificate/index'], resolve),
    hidden: true,
    meta: {
      keepAlive: false,
      login: false,
      title: '报名查询'
    }
  },
  { // 人社部资格证书报名修改页面
    name:'signUpQualificationCertificateUpdateIndex',
    path: '/signUpQualificationCertificateUpdateIndex',
    component: (resolve) => require(['@/views/signUp/qualificationCertificate/update'], resolve),
    hidden: true,
    meta: {
      keepAlive: false,
      login: false,
      title: '报名查询'
    }
  },
]

const router = new VueRouter({
  mode: 'history',
  base: process.env.BASE_URL,
  // 处理页面跳转自动滚动到最顶部
  scrollBehavior(to, from, savedPosition) {
    if (savedPosition) {
      return savedPosition
    } else {
      return { x: 0, y: 0 }
    }
  },
  routes
})

export default router
